package com.wnhz.work.jy.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.uuzuche.lib_zxing.activity.CodeUtils;
import com.wnhz.work.jy.BaseActivity;
import com.wnhz.work.jy.MyMain;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.adapter.ShoppingAdapter;
import com.wnhz.work.jy.bean.GenerateOrderBean;
import com.wnhz.work.jy.bean.ShoppingBean;

import org.xutils.x;

import java.text.DecimalFormat;
import java.util.ArrayList;

public class OrderCodeActivity extends BaseActivity implements View.OnClickListener {

    private ImageView qr_code;
    public Bitmap mBitmap = null;
    String textContent = "嘉轶金服";

    private String qrcode;
    private String guiyuanOrderid;
    private String pid;
    private String finalAllp;
    private ListView listView;

    private TextView title;
    private ArrayList<ShoppingBean> shopList = new ArrayList<>();
    private GenerateOrderBean generateOrderBean;
    private ShoppingAdapter mAdapter;
    private TextView allPrice;
    private TextView tv_pay_money;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_code);
        generateOrderBean = (GenerateOrderBean) getIntent().getSerializableExtra("bean");
        shopList.addAll(generateOrderBean.getGoodsData());
        /*qrcode = getIntent().getStringExtra("qrcode");
        guiyuanOrderid = getIntent().getStringExtra("guiyuanOrderid");
        pid = getIntent().getStringExtra("pid");
        finalAllp = getIntent().getStringExtra("finalAllp");*/
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("订单二维码");
        allPrice = (TextView) findViewById(R.id.allPrice);
        tv_pay_money = (TextView) findViewById(R.id.tv_pay_money);
        /*listView = (ListView) findViewById(R.id.listView);
        mAdapter = new ShoppingAdapter(this,shopList,this);
        listView.setAdapter(mAdapter);*/
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        qr_code = (ImageView) findViewById(R.id.qr_code);
        /*mBitmap = CodeUtils.createImage(textContent, 720, 720, null);
        qr_code.setImageBitmap(mBitmap);*/
        x.image().bind(qr_code,generateOrderBean.getQrcode());
        /*double money = 0;
        for (int i = 0; i < shopList.size(); i++) {
            money += Double.parseDouble(shopList.get(i).getGoodPrice())*Integer.parseInt(shopList.get(i).getGoodNumber());
        }
       *//* mAdapter.setType(1);
        mAdapter.notifyDataSetChanged();*//*
        DecimalFormat df = new DecimalFormat("##.##");*/
        tv_pay_money.setText("¥"+generateOrderBean.getPay_fee());
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_main_left:
                finish();
                break;
        }
    }

    @Override
    public void finish() {
        startActivity(new Intent(OrderCodeActivity.this, MyMain.class).putExtra("Pagination",4));
    }
}
